package com.slipper.system.codeless.service;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.slipper.util.Tool;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

import com.slipper.system.codeless.dao.ViewParamDao;
import com.slipper.system.codeless.bo.ViewParamBO;

import com.slipper.core.transaction.ReadTransactional;
import com.slipper.core.transaction.WriteTransactional;
import com.slipper.util.UUID;

@Service
@ReadTransactional
public class ViewParamService {
    @Resource
    private ViewParamDao viewParamDao;
    
    public ViewParamBO queryBy(String id) {
        return viewParamDao.queryBy(id);
    }
    
    public List<ViewParamBO> queryList(ViewParamBO bo) {
        return viewParamDao.queryList(bo);
    }
    
    public PageInfo<ViewParamBO> queryPage(ViewParamBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(viewParamDao.queryList(bo));
    }
    
    @WriteTransactional
    public int save(ViewParamBO bo) {
        if (Tool.isNotBlank(bo.getId())) {
            bo.setUpdateTime(System.currentTimeMillis());
            return viewParamDao.update(bo);
        } else {
            bo.setId(UUID.getUUID());
            bo.setUpdateTime(System.currentTimeMillis());
            bo.setCreateTime(System.currentTimeMillis());
            return viewParamDao.insert(bo);
        }
    }
    
    @WriteTransactional
    public int delete(ViewParamBO bo) {
        return viewParamDao.delete(bo);
    }
}
